package com.lin.manager.controller.tool;

import com.lin.manager.aop.Log;
import com.lin.manager.common.enums.LogEnum;
import com.lin.manager.common.req.QueryPage;
import com.lin.manager.common.resp.R;
import com.lin.manager.tool.entity.GenTable;
import com.lin.manager.tool.model.TableParamVo;
import com.lin.manager.tool.model.TableVo;
import com.lin.manager.tool.service.GeneratorDbService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author linjiang
 * @date 2024/5/15
 * @fn
 */
@Api(tags = "代码生成")
@RestController
@RequestMapping("gen")
public class GeneratorDbController {
    @Autowired
    private GeneratorDbService generatorDbService;

    @ApiOperation("代码生成 - 查询数据库业务表")
    @Log(module = "代码生成", descipt = "查询数据库业务表", type = LogEnum.SELECT)
    @GetMapping("selectTableFromDb")
    public R selectTableFromDb(TableParamVo tableVo) {
        return R.ok(generatorDbService.selectTableFromDb(tableVo));
    }

    @ApiOperation("代码生成 - 将业务表导入到系统中")
    @Log(module = "代码生成", descipt = "将业务表导入到系统中", type = LogEnum.INSERT)
    @PostMapping("importTableToSystem")
    public R importTableToSystem(@RequestBody GenTable genTable) {
        generatorDbService.importTableToSystem(genTable);
        return R.ok();
    }

    @ApiOperation("代码生成 - 查询系统业务表")
    @Log(module = "代码生成", descipt = "查询系统业务表", type = LogEnum.SELECT)
    @GetMapping("selectTableFromSystem")
    public R selectTableFromSystem(QueryPage page) {
        return R.ok(generatorDbService.selectTableFromSystem(page));
    }

    @ApiOperation("代码生成 - 删除系统业务表")
    @Log(module = "代码生成", descipt = "删除系统业务表", type = LogEnum.DELETE)
    @DeleteMapping("deleteTableFromSystem")
    public R deleteTableFromSystem(@RequestBody List<Integer> ids) {
        generatorDbService.deleteTableFromSystem(ids);
        return R.ok();
    }

    @ApiOperation("代码生成 - 查询系统业务表详情")
    @Log(module = "代码生成", descipt = "查询系统业务表详情", type = LogEnum.SELECT)
    @GetMapping("selectTableInfoById")
    public R selectTableInfoById(Integer id) {
        return R.ok(generatorDbService.selectTableInfoById(id));
    }

    @ApiOperation("代码生成 - 编辑系统业务表详情")
    @Log(module = "代码生成", descipt = "编辑系统业务表详情", type = LogEnum.UPDATE)
    @PostMapping("updateGenTable")
    public R updateGenTable(@RequestBody TableVo vo) {
        generatorDbService.updateGenTable(vo);
        return R.ok();
    }
}
